<?php 
class CCmsController extends CController{

	protected $m_objPage;
	
	function __construct() {
		parent::__construct();
		return true;
	}
	
	function initialize() {
		parent::initialize();
		return true;
	}
	
	function execute() {
		
		switch( $this->m_strAction ) {
			case NULL:	
				$this->handleViewPage();
				break;
			
			default:
				$this->handleViewPage();
				
		}
	}

	/*************************************
	********** HANDLE FUNCTIONS **********
	*************************************/
	
	function handleViewPage() {
		
		$intPageId = $this->m_objData->getGetData( array( 'id' ) );		
		if( true == isset( $intPageId ) ) {
			$this->m_objPage = CPages::fetchPageById( $intPageId, $this->m_objDatabase );
			
			$this->m_objAdvertisementCategory = CAdvertisementCategories::fetchAdvertisementCategorie( $this->m_objPage->getTitle(), $this->m_objDatabase);
			
			$this->m_arrobjAdvertisement = CAdvertisements::fetchAdvertisementsByModuleId( $this->m_objAdvertisementCategory->getId(), $this->m_objDatabase );
					
			//$this->m_arrobjAdvertisementTypes = CAdvertisementTypes::fetchAdvertisementTypeByIds($arrintId, $this->m_objDatabase );
		}	
		
		$this->displayViewPage();
	}

	/**************************************
	********** DISPLAY FUNCTIONS **********
	**************************************/	
		
	function displayViewPage() {
		parent::display();
		
		$this->m_objSmarty->assign_by_ref( 'page', $this->m_objPage );	
		$this->m_objSmarty->assign_by_ref( 'advertisement_categorie', $this->m_objAdvertisementCategory );
		$this->m_objSmarty->assign_by_ref( 'advertisements', $this->m_arrobjAdvertisement );
				
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/cms/view_page.tpl');

	}

}
?>